<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/gwcxx.css" type="text/css" rel="stylesheet"/>
<title>购物车</title>

<script src="js/jquery-1.5.1.min.js"/></script>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
	hideMain();
	setjsMoney();
	});


    function hideMain(){
    	var gwcxx="${lstGwcxx}";
    	if(gwcxx.length==2){
    		$("#mainHas").hide();
    	}else{
    		$("#mainNone").hide();
    	}
    }
	function setjsMoney(){
		
	}
    
    function DeleteOne(gwcxxid){
    	var yhxxid="${yhxxSession.yhxxid}";
    	var flag=confirm("您确定要删除该商品吗？");
    	if(flag==true){
    		$.ajax({
    			url: "delGwcxx.action",
    			type: "post",
    			data: "yhxxid="+yhxxid+"&gwcxxid="+gwcxxid,
    			datetype: "json",
    			success: function(date) {
    				window.location.reload(); 
    		     }
       		 });
    	}else{
    		return false;
    	}
    }
    //清空购物车
    function DeleteAll(){
    	var yhxxid="${yhxxSession.yhxxid}";
    	var flag=confirm("您确定要清空购物车吗？");
    	if(flag==true){
    		$.ajax({
    			url: "delGwcxx.action",
    			type: "post",
    			data: "yhxxid="+yhxxid,
    			datetype: "json",
    			success: function(date) {
    				if(date.flag=="1"){
    					window.location.reload(); 
    				}else{
    					alert("删除失败，请重试!");
    				}
    		     }
       		 });
    	}else{
    		return false;
    	}
    }
    //添加商品数量,需要ID 商品数量 商品库存jsMoney
    function addSpslClick(id,spsj){
    	
    	//var spsl=parseInt($("#spsl_"+id).val());
    	//spsl=spsl+1;
      //  var jsMoney=parseFloat($("#jsMoney").text());
      //  jsMoney=jsMoney+parseFloat(spsj);
      //  $("#spsl_"+id).val(spsl);
      //  $("#jsMoney").text(jsMoney);
    }
    //减去商品数量
    function downSpslClick(id,spsj){
    	var spsl=parseInt($("#spsl_"+id).val());
    	if(spsl<1){
    		spsl=spsl-1;
    	}
    	
       // var jsMoney=parseFloat($("#jsMoney").text());
       // jsMoney=jsMoney-parseFloat(spsj);
      //  $("#spsl_"+id).val(spsl);
       // $("#jsMoney").text(jsMoney);
    }
    //下单结算
    function xdjsClick(){
    	window.location.href="readyDdxx.action";
    	//var jsonObj="";
    	//jsonObj="[";
    	//$("#getSpdj>tr>td>div>input").each(function(index){
    	//	if(index!=0){
    	//		jsonObj+=",";
    	//	}
    	//	var gwcxxid=this.id.substring(5,this.id.length);
    	//	var spsl=$(this).val();
    //	    jsonObj+="{'gwcxxid':'"+gwcxxid+"',";
    //	    jsonObj+="'spsl':'"+spsl+"'}";
	//	});
    	//jsonObj+="]";
    //	//jsonObj=eval(jsonObj);
    	//alert(jsonObj);

	//	$.ajax({
	//		url: "updateGwcxx.action",
//		type: "post",
//		data: "jsonObj="+jsonObj,
	//		datetype: "json",
	//		success: function(date) {
			//if(date.flag=="1"){
				//	window.location.reload(); 
				//	window.location.href="updateGwcxx.action";
				//	window.location.href="readyDdxx.action";
				//}else{
					//alert("删除失败，请重试!");
				//}
	//	     }
   	//	 });
    }

</script>
</head>

<body>
<div class="container"><!--container begin-->
  <div class="header"><!--header begin-->
     <div class="top_nav">
        <ul>
          <li><a href="#">会员中心</a></li>
          <li><a href="#">我的订单</a></li>
          <li><a href="#">收藏夹</a></li>
          <li><a href="#">帮助中心</a></li>
        </ul>
     </div>
     <div class="logo">
       <a href="#"><img src="images/logo_m.png" /></a>
     </div>
  </div><!--header end-->
  <div style="clear:both;"></div>
  <div id="mainHas" class="main"><!--main begin-->
  <div class="gwzt"></div>
  <div class="mygwc"><b style="font-size:14px;">我的购物车</b></div>
  <div class="splist"><!--splist begin-->
    <table width="100%" style="border:1px solid #CCCCCC;">
      <thead>
        <tr>
           <th width="70">图片</th>
           <th>商品名称</th>
           <th>赠送积分</th>
           <th>销售价格</th>
           <th>数量</th>
           <th>优惠小计</th>
           <th>删除</th>
        </tr>
      </thead>
      <tbody id="getSpdj">
        <s:iterator value="lstGwcxx" status="list"><!-- 测试一下购物车session -->
        <tr>
          
          <td style="text-align:center; height:70px; "><img src="<s:property value="sptp" />" width="50" height="50" /></td>
          <td style="text-align:left; font-size:12px;">	<s:property value="spbt" />(<s:property value="spxhnr" />)</td>
          <td style="text-align:center;font-size:12px;">0</td>
          <td style="text-align:center; font-size:12px;">￥<span id="spsj_<s:property value="list.index" />"><s:property value="spsj" /></span></td>
          <td style="text-align:center; font-size:12px; width:70px;">
          <div class="NumInput">
            <input id="spsl_<s:property value="gwcxxid" />" value="<s:property value="spsl" />" type="text" style="width:20px; float:left;"/> 
            <div class="button">
              <div class="buttonup" onclick="addSpslClick(<s:property value="gwcxxid" />,<s:property value="spsj" />)"></div>
              <div class="buttondown" onclick="downSpslClick(<s:property value="gwcxxid" />,<s:property value="spsj" />)"></div>
            </div>
          </div> 
          </td>
          <td style="text-align:center; font-size:12px;">-</td>
          <td style="text-align:center; font-size:12px;"><a href="#" onclick="DeleteOne(<s:property value="gwcxxid" />)"><img src="images/gwcDelet.jpg"/></a></td>
        </tr>
        </s:iterator>
      </tbody>
    </table>
  </div><!--splist end-->
  <div class="main_spze"><!--商品列表-->
     <div style="width:180px; float:right;"><span style="color:#FF0000">商品总额：</span><span style="color:#970303; font-weight:bold;">
           ￥<span id="jsMoney">
          ${gwczje }
     </span></span></div>
  </div><!--商品列表 end-->
  <div class="main_xdjs"><!--下单结算区 begin-->
     <div class="main_xdjs_left">
       <span><a href="#"><img src="images/jxgwbutton.jpg" /></a></span><span style="margin-left:10px;"><a onclick="DeleteAll()" href="#"><img src="images/qkgwc.jpg" /></a></span>
     </div>
     <div class="main_xdjs_right">
       <input type="button" class="main_xdjs_right_button" onclick="xdjsClick()" value="下单结算"/>
     </div>
  </div><!--下单结算区 end-->
  </div><!--main end-->
  <div id="mainNone">
     <div style="margin-left:20px;margin-top:20px;font-weight:bold; font-size:14px;">购物车目前没有加入任何商品!</div>
     <div style="margin-left:20px;margin-top:30px;"><a href="#">继续挑选商品»»</a></div>
  </div>
  <div class="footer"><!--footer begin-->
  
  </div><!--footer end-->
</div><!--container end-->
</body>
</html>
	